cmake_minimum_required(VERSION 3.10.0)
project(OpenGateway VERSION 0.1.0 LANGUAGES C)


# 设置C/C++标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)

# 递归包含头文件目录（include及其子目录）
function(include_sub_directories_recursively root_dir)
    if(IS_DIRECTORY ${root_dir})
        message(STATUS "Adding include dir: ${root_dir}")
        include_directories(${root_dir})
    endif()
    
    file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*)
    foreach(sub ${ALL_SUB})
        if(IS_DIRECTORY ${root_dir}/${sub})
            include_sub_directories_recursively(${root_dir}/${sub})
        endif()
    endforeach()
endfunction()

# 递归包含头文件
include_sub_directories_recursively(${PROJECT_SOURCE_DIR}/inc)
include_sub_directories_recursively(${PROJECT_SOURCE_DIR}/third_party/libmodbus/include)
include_sub_directories_recursively(${PROJECT_SOURCE_DIR}/third_party/libmosquitto/include)



# 添加第三方库目录
link_directories(${PROJECT_SOURCE_DIR}/third_party/libmodbus/lib)
link_directories(${PROJECT_SOURCE_DIR}/third_party/libmosquitto/lib)



# 递归收集所有源文件
file(GLOB_RECURSE SOURCES "src/*.c" "main.c")

# 生成可执行文件
add_executable(${PROJECT_NAME} ${SOURCES})

# 链接第三方库（示例）
target_link_libraries(${PROJECT_NAME} modbus ssl uuid crypto mosquitto)

